home *** CD-ROM | disk | FTP | other *** search
- /*
- $Header: C:\THE\RCS\match.the 1.4 1993/09/01 16:27:20 MH Interim MH $
- */
- /***********************************************************************/
- /* Description: REXX macro to match pairs of keywords */
- /* Syntax: match */
- /* Notes: This macro will mark a line block enclosing all lines */
- /* that are enclosed by a matching pair of keywords. */
- /* Keywords can actually be more than 1 word, like */
- /* 'end if' but are specified as 1 word. */
- /* Supported keyword pairs are: */
- /* #if - #endif */
- /* begin - end; */
- /* do - end */
- /* if - endif */
- /* loop - endloop */
- /* Bugs: Only keywords that START a line are considered for */
- /* matching and each keyword must be on seperate lines. */
- /***********************************************************************/
- Trace o
- string.1 = '#IF #ENDIF >'
- string.2 = '#ENDIF #IF <'
- string.3 = 'BEGIN END; >'
- string.4 = 'END; BEGIN <'
- string.5 = 'DO END >'
- string.6 = 'END DO <'
- string.7 = 'IF ENDIF >'
- string.8 = 'ENDIF IF <'
- string.9 = 'LOOP ENDLOOP >'
- string.10 = 'ENDLOOP LOOP <'
- num_string = 10
-
- 'EXTRACT /LINE/CURLINE/'/* get the focus line contents and line number */
- save_current_line = line.1
- newline = ''
- Do i = 1 To Words(curline.3) /* get rid of all blanks in the line */
- newline = newline||Strip(Word(curline.3,i))
- End
- newline = Translate(newline) /* uppercase to match keywords */
- stridx = 0
- Do i = 1 To num_string /* find a keyword...*/
- source = Word(string.i,1)
- length = Length(source)
- If Substr(newline,1,length) = source Then
- Do
- stridx = i
- Leave
- End
- End
- If stridx = 0 Then /* if no keyword found, error */
- Do
- 'EMSG Unknown match string'
- Exit
- End
- num_source = 1
- num_target = 0
- source = Word(string.stridx,1)
- target = Word(string.stridx,2)
- direction = Word(string.stridx,3)
- Do Forever /* find matching keyword...*/
- If direction = '>' Then 'N'
- Else 'U'
- If rc \= 0 Then Leave
- 'EXTRACT /CURLINE/'
- newline = ''
- Do i = 1 To Words(curline.3)
- newline = newline||Strip(Word(curline.3,i))
- End
- newline = Translate(newline)
- Select
- When Substr(newline,1,Length(source)) = source Then num_source = num_source + 1
- When Substr(newline,1,Length(target)) = target Then num_target = num_target + 1
- Otherwise
- End
- If num_source = num_target Then /* if match found...*/
- Do
- 'reset block'
- 'mark line' /*...mark a line block */
- ':'||save_current_line
- 'mark line'
- Return
- End
- End
- 'EMSG No matching target' target 'found for' source
- ':'||save_current_line
- Return
-